package com.jyb.util.capture;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.alibaba.fastjson.JSON;
import com.jyb.config.HttpCilentConfig;
import com.jyb.enumeration.ShanghaiDistrict;
import com.jyb.util.UrlUtil;
import com.jyb.vo.GqxhVo;

public class GqxhUtil {

	public static List<GqxhVo> capture(ShanghaiDistrict district,String tdh){
		
		List<GqxhVo> list=new ArrayList<GqxhVo>();
		
		CloseableHttpClient httpclient = HttpClients.createDefault();
		CloseableHttpResponse response=null;
		try {
			
			if(ShanghaiDistrict.WY==district){
				String url="http://www.spict.com/portinfo/Normal/CTNGInfosPage.aspx";
				HttpGet httpGet = HttpCilentConfig.getHttpGet(url);
				response = httpclient.execute(httpGet);
				HttpEntity entity = response.getEntity();
				String str=EntityUtils.toString(entity);
				Document document=Jsoup.parse(str);
				Elements elements=document.select("input");
				
				HttpPost httpPost = new HttpPost("http://www.spict.com/portinfo/Normal/CTNGInfosPage.aspx");
				List <NameValuePair> nvps = new ArrayList <NameValuePair>();
				for (Element element : elements) {
					String name=element.attr("name");
					String val= element.val();
					if("ctl00_ASPxSplitter2_ContentPlaceHolder1_SearchPages_txtBLNO_Raw".equals(name)){
						nvps.add(new BasicNameValuePair(name,tdh));
					}else if("ctl00$ASPxSplitter2$ContentPlaceHolder1$SearchPages$txtBLNO".equals(name)){
						nvps.add(new BasicNameValuePair(name,tdh));
					}else{
						nvps.add(new BasicNameValuePair(name,val));
					}
					
				}
				httpPost.setEntity(new UrlEncodedFormEntity(nvps));
				CloseableHttpResponse response2 = httpclient.execute(httpPost);
				entity = response2.getEntity();
				str=EntityUtils.toString(entity);
				document=Jsoup.parse(str);
				elements=document.select("table[id=ctl00_ASPxSplitter2_ContentPlaceHolder1_gridView_DXMainTable]").select("tr:gt(1)");
				for (Element element : elements) {
					Elements elementTds=element.select("td");
					
					if(elementTds.size()>19){
						String oncilckEvent=elementTds.get(0).select("a").get(0).attr("href");
						oncilckEvent=oncilckEvent.substring(oncilckEvent.indexOf("'")+1,oncilckEvent.lastIndexOf("'"));
						String url2="http://www.spict.com/portinfo/Normal/CTNInfoPage.aspx?ctnno="+oncilckEvent;
						httpGet = HttpCilentConfig.getHttpGet(url2);
						response = httpclient.execute(httpGet);
						entity = response.getEntity();
						str=EntityUtils.toString(entity);
						document=Jsoup.parse(str);
						
						GqxhVo gqxhVo=new GqxhVo();
						gqxhVo.setShanghaiDistrict(district);
						gqxhVo.setGk(district.getTitle());
						gqxhVo.setXh(document.select("input[name=ctl00$ContentPlaceHolder1$tbxCTNNO]").get(0).val());
						gqxhVo.setCc(document.select("input[name=ctl00$ContentPlaceHolder1$tbxCTNSize]").get(0).val());
						gqxhVo.setXx(document.select("input[name=ctl00$ContentPlaceHolder1$tbxCTNType]").get(0).val());
						gqxhVo.setGd(document.select("input[name=ctl00$ContentPlaceHolder1$tbxCTNHeight]").get(0).val());
						gqxhVo.setZt(document.select("input[name=ctl00$ContentPlaceHolder1$tbxCTNStat]").get(0).val());
						gqxhVo.setQfh(document.select("input[name=ctl00$ContentPlaceHolder1$tbxSealNO]").get(0).val());
						gqxhVo.setTdh(document.select("input[name=ctl00$ContentPlaceHolder1$tbxBLNO]").get(0).val().replaceAll(",", "<br/>"));
						gqxhVo.setCxr(document.select("input[name=ctl00$ContentPlaceHolder1$tbxCTNOwner]").get(0).val());
						gqxhVo.setZl(document.select("input[name=ctl00$ContentPlaceHolder1$tbxCTNNetWeight]").get(0).val());
						gqxhVo.setLcxwd(document.select("input[name=ctl00$ContentPlaceHolder1$tbxRCTemperature]").get(0).val());
						gqxhVo.setWxplx(document.select("input[name=ctl00$ContentPlaceHolder1$tbxDGType]").get(0).val());
						gqxhVo.setWplhgbh(document.select("input[name=ctl00$ContentPlaceHolder1$tbxDGUNNO]").get(0).val());
						gqxhVo.setJhzyfs(document.select("input[name=ctl00$ContentPlaceHolder1$tbxCTNIOType]").get(0).val());
						gqxhVo.setJhzysj(document.select("input[name=ctl00$ContentPlaceHolder1$tbxETW]").get(0).val());
						gqxhVo.setJcsj(document.select("input[name=ctl00$ContentPlaceHolder1$tbxCTNRTIN]").get(0).val());
						gqxhVo.setCcsj(document.select("input[name=ctl00$ContentPlaceHolder1$tbxETW]").get(0).val());
						gqxhVo.setJcfs(document.select("input[name=ctl00$ContentPlaceHolder1$tbxCTNMIN]").get(0).val());
						gqxhVo.setCcfs(document.select("input[name=ctl00$ContentPlaceHolder1$tbxCTNMOUT]").get(0).val());
						gqxhVo.setXbksj(document.select("input[name=ctl00$ContentPlaceHolder1$tbxTCTNEmpty]").get(0).val());
						gqxhVo.setXbkyy(document.select("input[name=ctl00$ContentPlaceHolder1$tbxRCTNEmpty]").get(0).val());
						gqxhVo.setYcccm(document.select("input[name=ctl00$ContentPlaceHolder1$tbxFirstVVessel]").get(0).val());
						gqxhVo.setYcchc(document.select("input[name=ctl00$ContentPlaceHolder1$tbxFirstVVoyage]").get(0).val());
						gqxhVo.setEcccm(document.select("input[name=ctl00$ContentPlaceHolder1$tbxSecondVVessel]").get(0).val());
						gqxhVo.setEcchc(document.select("input[name=ctl00$ContentPlaceHolder1$tbxSecondVVoyage]").get(0).val());
						gqxhVo.setZhg(document.select("input[name=ctl00$ContentPlaceHolder1$tbxLoadingPort]").get(0).val());
						gqxhVo.setXhg(document.select("input[name=ctl00$ContentPlaceHolder1$tbxDischargingPort]").get(0).val());
						gqxhVo.setMdg(document.select("input[name=ctl00$ContentPlaceHolder1$tbxDestinationPort]").get(0).val());
						gqxhVo.setMtfg(document.select("input[name=ctl00$ContentPlaceHolder1$tbxIsCustomsRelease]").get(0).val());
						gqxhVo.setPc(document.select("input[name=ctl00$ContentPlaceHolder1$tbxIsDS]").get(0).val());
						gqxhVo.setCxw(document.select("input[name=ctl00$ContentPlaceHolder1$tbxCTNYardSlot]").get(0).val());
						gqxhVo.setCxxlx(document.select("input[name=ctl00$ContentPlaceHolder1$tbxOverCTNType]").get(0).val());
						gqxhVo.setCz(document.select("input[name=ctl00$ContentPlaceHolder1$tbxOverWeight]").get(0).val());
						gqxhVo.setCg(document.select("input[name=ctl00$ContentPlaceHolder1$tbxOverHeight]").get(0).val());
						gqxhVo.setQcc(document.select("input[name=ctl00$ContentPlaceHolder1$tbxFOL]").get(0).val());
						gqxhVo.setHcc(document.select("input[name=ctl00$ContentPlaceHolder1$tbxBOL]").get(0).val());
						gqxhVo.setZck(document.select("input[name=ctl00$ContentPlaceHolder1$tbxLOW]").get(0).val());
						gqxhVo.setYck(document.select("input[name=ctl00$ContentPlaceHolder1$tbxROW]").get(0).val());
						gqxhVo.setTxm(document.select("input[name=ctl00$ContentPlaceHolder1$tbxIsTurnCTN]").get(0).val());
						gqxhVo.setFph(document.select("input[name=ctl00$ContentPlaceHolder1$tbxInvoiceNO]").get(0).val());
						gqxhVo.setCsbj(document.select("input[name=ctl00$ContentPlaceHolder1$tbxIsDamaged]").get(0).val());
						
						list.add(gqxhVo);
					}
					
				}
				
				
			}else if(ShanghaiDistrict.WE==district){
				String url="http://www.sipgzct.com/wat/controllerServlet.do?queryid=0003003&method=doquery&billnoinput="+tdh;
				url=UrlUtil.hanadleUrl(url);
				
				HttpGet httpGet = HttpCilentConfig.getHttpGet(url);
				response = httpclient.execute(httpGet);
				HttpEntity entity = response.getEntity();
				String str=EntityUtils.toString(entity);
				Document document=Jsoup.parse(str);
				
				Elements elements=document.select("table[class=ltable]").get(0).select("tr:gt(0)");
				for (Element element : elements) {
					Elements elementTds=element.select("td");
					
					if(elementTds.size()>=9){
						
						GqxhVo gqxhVo=new GqxhVo();
						gqxhVo.setGk(district.getTitle());
						gqxhVo.setShanghaiDistrict(district);
						
						String oncilckEvent=elementTds.get(10).select("img").get(0).attr("onclick");
						oncilckEvent=oncilckEvent.substring(oncilckEvent.indexOf("\"")+1,oncilckEvent.lastIndexOf("\""));
						String[] oncilckEvents=oncilckEvent.split("##");
						for (String string : oncilckEvents) {
							String[] strings=string.split(":=");
							if(strings.length==2){
								if("箱号".equals(strings[0])){
									gqxhVo.setXh(strings[1]);
								}else if("尺寸".equals(strings[0])){
									gqxhVo.setCc(strings[1]);
								}else if("箱型".equals(strings[0])){
									gqxhVo.setXx(strings[1]);
								}else if("高度".equals(strings[0])){
									gqxhVo.setGd(strings[1]);
								}else if("状态".equals(strings[0])){
									gqxhVo.setZt(strings[1]);
								}else if("铅封号".equals(strings[0])){
									gqxhVo.setQfh(strings[1]);
								}else if("提单号".equals(strings[0])){
									gqxhVo.setTdh(strings[1]);
								}else if("持箱人".equals(strings[0])){
									gqxhVo.setCxr(strings[1]);
								}else if("重量".equals(strings[0])){
									gqxhVo.setZl(strings[1]);
								}else if("冷藏箱温度".equals(strings[0])){
									gqxhVo.setLcxwd(strings[1]);
								}else if("危险品类型".equals(strings[0])){
									gqxhVo.setWxplx(strings[1]);
								}else if("计划作业方式".equals(strings[0])){
									gqxhVo.setJhzyfs(strings[1]);
								}else if("计划作业".equals(strings[0])){
									gqxhVo.setJhzysj(strings[1]);
								}else if("进场时间".equals(strings[0])){
									gqxhVo.setJcsj(strings[1]);
								}else if("出场时间".equals(strings[0])){
									gqxhVo.setCcsj(strings[1]);
								}else if("进场方式".equals(strings[0])){
									gqxhVo.setJcfs(strings[1]);
								}else if("出场方式".equals(strings[0])){
									gqxhVo.setCcfs(strings[1]);
								}else if("流向".equals(strings[0])){
									gqxhVo.setLx(strings[1]);
								}else if("箱变空".equals(strings[0])){
									gqxhVo.setXbksj(strings[1]);
								}else if("箱变空原因".equals(strings[0])){
									gqxhVo.setXbkyy(strings[1]);
								}else if("一程船船名".equals(strings[0])){
									gqxhVo.setYcccm(strings[1]);
								}else if("一程船航次".equals(strings[0])){
									gqxhVo.setYcchc(strings[1]);
								}else if("二程船船名".equals(strings[0])){
									gqxhVo.setEcccm(strings[1]);
								}else if("二程船航次".equals(strings[0])){
									gqxhVo.setEcchc(strings[1]);
								}else if("装货港".equals(strings[0])){
									gqxhVo.setZhg(strings[1]);
								}else if("卸货港".equals(strings[0])){
									gqxhVo.setXhg(strings[1]);
								}else if("目的港".equals(strings[0])){
									gqxhVo.setMdg(strings[1]);
								}else if("是否配载".equals(strings[0])){
									gqxhVo.setPc(strings[1]);
								}else if("放关".equals(strings[0])){
									gqxhVo.setMtfg(strings[1]);
								}else if("超限箱类型".equals(strings[0])){
									gqxhVo.setCxxlx(strings[1]);
								}else if("超重".equals(strings[0])){
									gqxhVo.setCz(strings[1]);
								}else if("超高".equals(strings[0])){
									gqxhVo.setCg(strings[1]);
								}else if("前超长".equals(strings[0])){
									gqxhVo.setCc(strings[1]);
								}else if("后超长".equals(strings[0])){
									gqxhVo.setHcc(strings[1]);
								}else if("左超宽".equals(strings[0])){
									gqxhVo.setZck(strings[1]);
								}else if("右超宽".equals(strings[0])){
									gqxhVo.setYck(strings[1]);
								}else if("联动码头".equals(strings[0])){
									gqxhVo.setLdmt(strings[1]);
								}else if("场箱位".equals(strings[0])){
									gqxhVo.setCxw(strings[1]);
								}
							}
						}
						
						list.add(gqxhVo);
					}
				}
				
			}else if(ShanghaiDistrict.WS==district){
				String url="http://www.sect.com.cn/wat/controllerServlet.do?queryid=0003003&method=doquery&billnoinput="+tdh+"";
				url=UrlUtil.hanadleUrl(url);
				
				HttpGet httpGet = HttpCilentConfig.getHttpGet(url);
				response = httpclient.execute(httpGet);
				HttpEntity entity = response.getEntity();
				String str=EntityUtils.toString(entity);
				Document document=Jsoup.parse(str);
				
				Elements elements=document.select("table[class=ltable]").get(0).select("tr:gt(0)");
				for (Element element : elements) {
					Elements elementTds=element.select("td");
					
					if(elementTds.size()>=4){
						GqxhVo gqxhVo=new GqxhVo();
						gqxhVo.setGk(district.getTitle());
						gqxhVo.setShanghaiDistrict(district);
						
						String oncilckEvent=elementTds.get(9).select("img").get(0).attr("onclick");
						oncilckEvent=oncilckEvent.substring(oncilckEvent.indexOf("\"")+1,oncilckEvent.lastIndexOf("\""));
						String[] oncilckEvents=oncilckEvent.split("##");
						for (String string : oncilckEvents) {
							String[] strings=string.split(":=");
							if(strings.length==2){
								if("箱号".equals(strings[0])){
									gqxhVo.setXh(strings[1]);
								}else if("尺寸".equals(strings[0])){
									gqxhVo.setCc(strings[1]);
								}else if("箱型".equals(strings[0])){
									gqxhVo.setXx(strings[1]);
								}else if("高度".equals(strings[0])){
									gqxhVo.setGd(strings[1]);
								}else if("状态".equals(strings[0])){
									gqxhVo.setZt(strings[1]);
								}else if("铅封号".equals(strings[0])){
									gqxhVo.setQfh(strings[1]);
								}else if("提单号".equals(strings[0])){
									gqxhVo.setTdh(strings[1]);
								}else if("持箱人".equals(strings[0])){
									gqxhVo.setCxr(strings[1]);
								}else if("重量".equals(strings[0])){
									gqxhVo.setZl(strings[1]);
								}else if("冷藏箱温度".equals(strings[0])){
									gqxhVo.setLcxwd(strings[1]);
								}else if("危险品类型".equals(strings[0])){
									gqxhVo.setWxplx(strings[1]);
								}else if("计划作业方式".equals(strings[0])){
									gqxhVo.setJhzyfs(strings[1]);
								}else if("计划作业".equals(strings[0])){
									gqxhVo.setJhzysj(strings[1]);
								}else if("进场时间".equals(strings[0])){
									gqxhVo.setJcsj(strings[1]);
								}else if("出场时间".equals(strings[0])){
									gqxhVo.setCcsj(strings[1]);
								}else if("进场方式".equals(strings[0])){
									gqxhVo.setJcfs(strings[1]);
								}else if("出场方式".equals(strings[0])){
									gqxhVo.setCcfs(strings[1]);
								}else if("流向".equals(strings[0])){
									gqxhVo.setLx(strings[1]);
								}else if("箱变空".equals(strings[0])){
									gqxhVo.setXbksj(strings[1]);
								}else if("箱变空原因".equals(strings[0])){
									gqxhVo.setXbkyy(strings[1]);
								}else if("一程船船名".equals(strings[0])){
									gqxhVo.setYcccm(strings[1]);
								}else if("一程船航次".equals(strings[0])){
									gqxhVo.setYcchc(strings[1]);
								}else if("二程船船名".equals(strings[0])){
									gqxhVo.setEcccm(strings[1]);
								}else if("二程船航次".equals(strings[0])){
									gqxhVo.setEcchc(strings[1]);
								}else if("装货港".equals(strings[0])){
									gqxhVo.setZhg(strings[1]);
								}else if("卸货港".equals(strings[0])){
									gqxhVo.setXhg(strings[1]);
								}else if("目的港".equals(strings[0])){
									gqxhVo.setMdg(strings[1]);
								}else if("是否配载".equals(strings[0])){
									gqxhVo.setPc(strings[1]);
								}else if("放关".equals(strings[0])){
									gqxhVo.setMtfg(strings[1]);
								}else if("超限箱类型".equals(strings[0])){
									gqxhVo.setCxxlx(strings[1]);
								}else if("超重".equals(strings[0])){
									gqxhVo.setCz(strings[1]);
								}else if("超高".equals(strings[0])){
									gqxhVo.setCg(strings[1]);
								}else if("前超长".equals(strings[0])){
									gqxhVo.setCc(strings[1]);
								}else if("后超长".equals(strings[0])){
									gqxhVo.setHcc(strings[1]);
								}else if("左超宽".equals(strings[0])){
									gqxhVo.setZck(strings[1]);
								}else if("右超宽".equals(strings[0])){
									gqxhVo.setYck(strings[1]);
								}else if("联动码头".equals(strings[0])){
									gqxhVo.setLdmt(strings[1]);
								}else if("场箱位".equals(strings[0])){
									gqxhVo.setCxw(strings[1]);
								}
							}
						}
						
						list.add(gqxhVo);
					}
					
				}
				
			}else if(ShanghaiDistrict.WW==district){
				String url="http://www.smct.com.cn/wat/controllerServlet.do?queryid=0003003&method=doquery&billnoinput="+tdh;
				url=UrlUtil.hanadleUrl(url);
				
				HttpGet httpGet = HttpCilentConfig.getHttpGet(url);
				response = httpclient.execute(httpGet);
				HttpEntity entity = response.getEntity();
				String str=EntityUtils.toString(entity);
				Document document=Jsoup.parse(str);
				
				Elements elements=document.select("table[class=ltable]").get(0).select("tr:gt(0)");
				for (Element element : elements) {
					Elements elementTds=element.select("td");
					if(elementTds.size()>=4){
						GqxhVo gqxhVo=new GqxhVo();
						gqxhVo.setGk(district.getTitle());
						gqxhVo.setShanghaiDistrict(district);
						
						String oncilckEvent=elementTds.get(10).select("img").get(0).attr("onclick");
						oncilckEvent=oncilckEvent.substring(oncilckEvent.indexOf("\"")+1,oncilckEvent.lastIndexOf("\""));
						String[] oncilckEvents=oncilckEvent.split("##");
						for (String string : oncilckEvents) {
							String[] strings=string.split(":=");
							if(strings.length==2){
								if("箱号".equals(strings[0])){
									gqxhVo.setXh(strings[1]);
								}else if("尺寸".equals(strings[0])){
									gqxhVo.setCc(strings[1]);
								}else if("箱型".equals(strings[0])){
									gqxhVo.setXx(strings[1]);
								}else if("高度".equals(strings[0])){
									gqxhVo.setGd(strings[1]);
								}else if("状态".equals(strings[0])){
									gqxhVo.setZt(strings[1]);
								}else if("铅封号".equals(strings[0])){
									gqxhVo.setQfh(strings[1]);
								}else if("提单号".equals(strings[0])){
									gqxhVo.setTdh(strings[1]);
								}else if("持箱人".equals(strings[0])){
									gqxhVo.setCxr(strings[1]);
								}else if("重量".equals(strings[0])){
									gqxhVo.setZl(strings[1]);
								}else if("冷藏箱温度".equals(strings[0])){
									gqxhVo.setLcxwd(strings[1]);
								}else if("危险品类型".equals(strings[0])){
									gqxhVo.setWxplx(strings[1]);
								}else if("计划作业方式".equals(strings[0])){
									gqxhVo.setJhzyfs(strings[1]);
								}else if("计划作业".equals(strings[0])){
									gqxhVo.setJhzysj(strings[1]);
								}else if("进场时间".equals(strings[0])){
									gqxhVo.setJcsj(strings[1]);
								}else if("出场时间".equals(strings[0])){
									gqxhVo.setCcsj(strings[1]);
								}else if("进场方式".equals(strings[0])){
									gqxhVo.setJcfs(strings[1]);
								}else if("出场方式".equals(strings[0])){
									gqxhVo.setCcfs(strings[1]);
								}else if("流向".equals(strings[0])){
									gqxhVo.setLx(strings[1]);
								}else if("箱变空".equals(strings[0])){
									gqxhVo.setXbksj(strings[1]);
								}else if("箱变空原因".equals(strings[0])){
									gqxhVo.setXbkyy(strings[1]);
								}else if("一程船船名".equals(strings[0])){
									gqxhVo.setYcccm(strings[1]);
								}else if("一程船航次".equals(strings[0])){
									gqxhVo.setYcchc(strings[1]);
								}else if("二程船船名".equals(strings[0])){
									gqxhVo.setEcccm(strings[1]);
								}else if("二程船航次".equals(strings[0])){
									gqxhVo.setEcchc(strings[1]);
								}else if("装货港".equals(strings[0])){
									gqxhVo.setZhg(strings[1]);
								}else if("卸货港".equals(strings[0])){
									gqxhVo.setXhg(strings[1]);
								}else if("目的港".equals(strings[0])){
									gqxhVo.setMdg(strings[1]);
								}else if("配船".equals(strings[0])){
									gqxhVo.setPc(strings[1]);
								}else if("空箱放关".equals(strings[0])){
									gqxhVo.setKxfg(strings[1]);
								}else if("放关".equals(strings[0])){
									gqxhVo.setMtfg(strings[1]);
								}else if("超限箱类型".equals(strings[0])){
									gqxhVo.setCxxlx(strings[1]);
								}else if("超重".equals(strings[0])){
									gqxhVo.setCz(strings[1]);
								}else if("超高".equals(strings[0])){
									gqxhVo.setCg(strings[1]);
								}else if("前超长".equals(strings[0])){
									gqxhVo.setCc(strings[1]);
								}else if("后超长".equals(strings[0])){
									gqxhVo.setHcc(strings[1]);
								}else if("左超宽".equals(strings[0])){
									gqxhVo.setZck(strings[1]);
								}else if("右超宽".equals(strings[0])){
									gqxhVo.setYck(strings[1]);
								}else if("联动码头".equals(strings[0])){
									gqxhVo.setLdmt(strings[1]);
								}else if("场箱位".equals(strings[0])){
									gqxhVo.setCxw(strings[1]);
								}else if("调箱门".equals(strings[0])){
									gqxhVo.setTxm(strings[1]);
								}else if("发票号".equals(strings[0])){
									gqxhVo.setFph(strings[1]);
								}else if("残损标记".equals(strings[0])){
									gqxhVo.setCsbj(strings[1]);
								}else if("装卸泊位".equals(strings[0])){
									gqxhVo.setZxbw(strings[1]);
								}else if("装卸码头".equals(strings[0])){
									gqxhVo.setZxmt(strings[1]);
								}
							}
						}
						
						list.add(gqxhVo);
					}
				}
				
			}else if(ShanghaiDistrict.YY==district){
				
				String url="http://cx.shsict.com:8100/wat/controllerServlet.do?queryid=0003003&method=doquery&billnoinput="+tdh;
				url=UrlUtil.hanadleUrl(url);
				
				HttpGet httpGet = HttpCilentConfig.getHttpGet(url);
				response = httpclient.execute(httpGet);
				HttpEntity entity = response.getEntity();
				String str=EntityUtils.toString(entity);
				Document document=Jsoup.parse(str);
				
				Elements elements=document.select("table[class=ltable]").get(0).select("tr:gt(0)");
				for (Element element : elements) {
					Elements elementTds=element.select("td");
					
					if(elementTds.size()>=9){

						GqxhVo gqxhVo=new GqxhVo();
						gqxhVo.setGk(district.getTitle());
						gqxhVo.setShanghaiDistrict(district);
						
						String oncilckEvent=elementTds.get(10).select("img").get(0).attr("onclick");
						oncilckEvent=oncilckEvent.substring(oncilckEvent.indexOf("\"")+1,oncilckEvent.lastIndexOf("\""));
						String[] oncilckEvents=oncilckEvent.split("##");
						for (String string : oncilckEvents) {
							String[] strings=string.split(":=");
							if(strings.length==2){
								if("箱号".equals(strings[0])){
									gqxhVo.setXh(strings[1]);
								}else if("尺寸".equals(strings[0])){
									gqxhVo.setCc(strings[1]);
								}else if("箱型".equals(strings[0])){
									gqxhVo.setXx(strings[1]);
								}else if("高度".equals(strings[0])){
									gqxhVo.setGd(strings[1]);
								}else if("状态".equals(strings[0])){
									gqxhVo.setZt(strings[1]);
								}else if("铅封号".equals(strings[0])){
									gqxhVo.setQfh(strings[1]);
								}else if("提单号".equals(strings[0])){
									gqxhVo.setTdh(strings[1]);
								}else if("持箱人".equals(strings[0])){
									gqxhVo.setCxr(strings[1]);
								}else if("重量".equals(strings[0])){
									gqxhVo.setZl(strings[1]);
								}else if("冷藏箱温度".equals(strings[0])){
									gqxhVo.setLcxwd(strings[1]);
								}else if("危险品类型".equals(strings[0])){
									gqxhVo.setWxplx(strings[1]);
								}else if("计划作业方式".equals(strings[0])){
									gqxhVo.setJhzyfs(strings[1]);
								}else if("计划作业".equals(strings[0])){
									gqxhVo.setJhzysj(strings[1]);
								}else if("进场时间".equals(strings[0])){
									gqxhVo.setJcsj(strings[1]);
								}else if("出场时间".equals(strings[0])){
									gqxhVo.setCcsj(strings[1]);
								}else if("进场方式".equals(strings[0])){
									gqxhVo.setJcfs(strings[1]);
								}else if("出场方式".equals(strings[0])){
									gqxhVo.setCcfs(strings[1]);
								}else if("流向".equals(strings[0])){
									gqxhVo.setLx(strings[1]);
								}else if("箱变空".equals(strings[0])){
									gqxhVo.setXbksj(strings[1]);
								}else if("箱变空原因".equals(strings[0])){
									gqxhVo.setXbkyy(strings[1]);
								}else if("一程船船名".equals(strings[0])){
									gqxhVo.setYcccm(strings[1]);
								}else if("一程船航次".equals(strings[0])){
									gqxhVo.setYcchc(strings[1]);
								}else if("二程船船名".equals(strings[0])){
									gqxhVo.setEcccm(strings[1]);
								}else if("二程船航次".equals(strings[0])){
									gqxhVo.setEcchc(strings[1]);
								}else if("装货港".equals(strings[0])){
									gqxhVo.setZhg(strings[1]);
								}else if("卸货港".equals(strings[0])){
									gqxhVo.setXhg(strings[1]);
								}else if("目的港".equals(strings[0])){
									gqxhVo.setMdg(strings[1]);
								}else if("配船".equals(strings[0])){
									gqxhVo.setPc(strings[1]);
								}else if("空箱放关".equals(strings[0])){
									gqxhVo.setKxfg(strings[1]);
								}else if("码头放关".equals(strings[0])){
									gqxhVo.setMtfg(strings[1]);
								}else if("国检放关".equals(strings[0])){
									gqxhVo.setGjfg(strings[1]);
								}else if("国检查验".equals(strings[0])){
									gqxhVo.setGjcy(strings[1]);
								}else if("海事危品放关".equals(strings[0])){
									gqxhVo.setHswpfg(strings[1]);
								}else if("超限箱类型".equals(strings[0])){
									gqxhVo.setCxxlx(strings[1]);
								}else if("超重".equals(strings[0])){
									gqxhVo.setCz(strings[1]);
								}else if("超高".equals(strings[0])){
									gqxhVo.setCg(strings[1]);
								}else if("前超长".equals(strings[0])){
									gqxhVo.setCc(strings[1]);
								}else if("后超长".equals(strings[0])){
									gqxhVo.setHcc(strings[1]);
								}else if("左超宽".equals(strings[0])){
									gqxhVo.setZck(strings[1]);
								}else if("右超宽".equals(strings[0])){
									gqxhVo.setYck(strings[1]);
								}else if("联动码头".equals(strings[0])){
									gqxhVo.setLdmt(strings[1]);
								}else if("场箱位".equals(strings[0])){
									gqxhVo.setCxw(strings[1]);
								}else if("调箱门".equals(strings[0])){
									gqxhVo.setTxm(strings[1]);
								}else if("发票号".equals(strings[0])){
									gqxhVo.setFph(strings[1]);
								}else if("残损标记".equals(strings[0])){
									gqxhVo.setCsbj(strings[1]);
								}else if("装卸泊位".equals(strings[0])){
									gqxhVo.setZxbw(strings[1]);
								}else if("装卸码头".equals(strings[0])){
									gqxhVo.setZxmt(strings[1]);
								}else if("联动码头".equals(strings[0])){
									gqxhVo.setLdmt(strings[1]);
								}
							}
						}
						
						list.add(gqxhVo);
					}
					
				}
				
			}else if(ShanghaiDistrict.YS==district){
				String url="http://www.sgict.com.cn:7001/query/search/comm/contgoods.jsp?choice=2&billno="+tdh;
				url=UrlUtil.hanadleUrl(url);
				
				HttpGet httpGet = HttpCilentConfig.getHttpGet(url);
				response = httpclient.execute(httpGet);
				HttpEntity entity = response.getEntity();
				String str=EntityUtils.toString(entity);
				Document document=Jsoup.parse(str);
				
				if(document.select("tr[class=result_th]").size()>0){
					Elements elements=document.select("tr[class=result_th]").get(0).parent().select("tr:gt(0)");
					int i=0;
					for (Element element : elements) {
						if(element.hasAttr("onclick")){
							Elements elementTds=element.select("td");
							if(elementTds.size()>=4){
								GqxhVo gqxhVo=new GqxhVo();
								gqxhVo.setGk(district.getTitle());
								gqxhVo.setShanghaiDistrict(district);
								
								Elements elements2=document.select("tr[id=row"+i+"]").get(0).select("table").get(0).select("tr");
								Map<String,String> map=new HashMap<String, String>();
								for (Element element2 : elements2) {
									Elements elements3=element2.select("td");
									if(elements3.size()>=4){
										map.put(elements3.get(0).text().replaceAll("：", ""), elements3.get(1).html());
										map.put(elements3.get(2).text().replaceAll("：", ""), elements3.get(3).html());
									}
								}
								
								gqxhVo.setXh(map.get("箱号"));
								gqxhVo.setCc(map.get("尺寸"));
								gqxhVo.setXx(map.get("箱型"));
								gqxhVo.setGd(map.get("高度"));
								gqxhVo.setZt(map.get("状态"));
								gqxhVo.setQfh(map.get("铅封号"));
								gqxhVo.setTdh(map.get("提单号"));
								gqxhVo.setCxr(map.get("持箱人"));
								gqxhVo.setZl(map.get("重量"));
								gqxhVo.setLcxwd(map.get("冷藏箱温度"));
								gqxhVo.setWxplx(map.get("危险品类型"));
								gqxhVo.setWplhgbh(map.get("危品联合国编号"));
								gqxhVo.setJhzyfs(map.get("计划作业方式"));
								gqxhVo.setJhzysj(map.get("计划作业时间"));
								gqxhVo.setJcsj(map.get("进场时间"));
								gqxhVo.setCcsj(map.get("出场时间"));
								gqxhVo.setJcfs(map.get("进场方式"));
								gqxhVo.setCcfs(map.get("出场方式"));
								gqxhVo.setXbksj(map.get("箱变空时间"));
								gqxhVo.setXbkyy(map.get("箱变空原因"));
								gqxhVo.setYcccm(map.get("一程船船名"));
								gqxhVo.setYcchc(map.get("一程船航次"));
								gqxhVo.setEcccm(map.get("二程船船名"));
								gqxhVo.setEcchc(map.get("二程船航次"));
								gqxhVo.setZhg(map.get("装货港"));
								gqxhVo.setXhg(map.get("卸货港"));
								gqxhVo.setMdg(map.get("目的港"));
								gqxhVo.setMtfg(map.get("放关"));
								gqxhVo.setPc(map.get("配船"));
								gqxhVo.setCxw(map.get("场箱位"));
								gqxhVo.setCxxlx(map.get("配超限箱类型"));
								gqxhVo.setCz(map.get("超重"));
								gqxhVo.setCg(map.get("超高"));
								gqxhVo.setQcc(map.get("前超长"));
								gqxhVo.setHcc(map.get("后超长"));
								gqxhVo.setZck(map.get("左超宽"));
								gqxhVo.setYck(map.get("右超宽"));
								
								list.add(gqxhVo);
							}
							
							i++;
						}
						
					}
				}
				
			}
			
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(response!=null){
				try {
					response.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		System.out.println(JSON.toJSONString(list));
		return list;
	} 
	
	public static void main(String[] args) {
		String oncilckEvent="todetail(\"箱号:=TGHU2581576##尺寸:=20´##箱型:=GP/普通##高度:=8´6´´##状态:=出口重箱##铅封号:=5665032##提单号:=SNKO020150608807<BR>货重:15100;件数:36;体积:18;##持箱人:=SNKO/长锦商船（中国）船务有限公司##重量:=17300##冷藏箱温度:=##危险品类型:=##危品联合国编号:=##计划作业方式:=##计划作业:=##进场时间:=15-07-05 21:14##出场时间:=07-07 19:41##进场方式:=出口重箱进场##出场方式:=装船出场##箱变空:=##箱变空原因:=##一程船船名:=##一程船航次:=##二程船船名:=DONGJIN VENUS/东进维纳斯##二程船航次:=1527E##装货港:=CNSHA/上海##卸货港:=KRPUS/釜山##目的港:=KRPUS/釜山##放关:=Y##空箱放关:=N##配船:=--##场箱位:=##超限箱类型:=## :=##超重:=##超高:=##前超长:=##后超长:=##左超宽:=##右超宽:=##调箱门:=N##发票号:=12788416,06604287,12892756##残损标记:=无残损##装卸泊位:=##装卸码头:=\");";
		
		oncilckEvent=oncilckEvent.substring(oncilckEvent.indexOf("\"")+1,oncilckEvent.lastIndexOf("\""));
		String[] oncilckEvents=oncilckEvent.split("##");
		for (String string : oncilckEvents) {
			String[] strings=string.split(":=");
			for (String string2 : strings) {
				System.out.print(" "+string2);
			}
			System.out.println();
		}
	}
}
